<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>土 豆 小 屋</title>
		<!-- 样 式 文 件 -->
		<link rel="stylesheet" href="component/pear/css/pear.css" />
		<link rel="stylesheet" href="component/layui/css/layui.css" media="all"/>
		<link rel="stylesheet" href="admin/css/other/login.css" />
	</head>
    <!-- 代 码 结 构 -->
	<body background="admin/images/background2.svg" style="background-size: cover;">
		<form class="layui-form" action="javascript:void(0);">
			<div class="layui-form-item">
				<img class="logo" src="admin/images/logo.png" />
				<div class="title">米 奇 妙 妙 屋</div>
				<div class="desc">
					什 么 乱 七 八 糟 都 有 的 米 奇 妙 妙 屋
				</div>
			</div>
			<div class="layui-form-item">
				<input placeholder="账 户 : " hover class="layui-input" name="username" value="admin"/>
			</div>
			<div class="layui-form-item">
				<input placeholder="密 码 : " hover class="layui-input"  name="password" type="password" value="admin"/>
			</div>
			<div class="layui-form-item">
				<input placeholder="验证码 : "  hover class="code layui-input layui-input-inline" value="VBJFQ"/>
				<img src="admin/images/captcha.gif" class="codeImage" />
			</div>
			<div class="layui-form-item">
				<input type="checkbox" title="记住密码" lay-skin="primary" checked name="remember">
			</div>
			<div class="layui-form-item">
				<button type="button" class="pear-btn pear-btn-success login" lay-submit lay-filter="login">
					登  入
				</button>
			</div>
			<div class="layui-btn-container">
				<button type="button" class="pear-btn pear-btn-success" id="register">
					注  册
				</button>
			</div>
		</form>
		<a href="http://beian.miit.gov.cn/" target="_blank">蜀ICP备2021007852号-1</a>
		<!-- 资 源 引 入 -->
		<script src="component/layui/layui.js"></script>
		<script src="component/pear/pear.js"></script>
		<script>
			layui.use(['form', 'button', 'popup', 'common'], function() {
				var form = layui.form;
				var button = layui.button;
				var popup = layui.popup;
				var $ = layui.$;
				let common = layui.common;

                // 登 录 提 交
				form.on('submit(login)', function(data) {
					//使用ajax发送请求
					console.log(data.field)
					$.ajax({
						url:"/Admin/login",
						type:"post",
						contentType:"application/json",
						data: JSON.stringify(data.field),
						dataType:"json",
						success:function(res){
							if(res.code === 0){
								button.load({
									elem: '.login',
									time: 1000,
									done: function() {
										popup.success(res.msg, function() {
											location.href = "/index.html"
										});
									}
								})
							}
							else{
								button.load({
									elem: '.login',
									time: 1500,
									done: function() {
										popup.success(res.msg, function() {
											location.href = "/login.html"
										});
									}
								})
							}
						}
					});
					return false;
				
				});

				$("#register").click(function(){
					layer.open({
						type: 2,
						title: '注册',
						shade: 0.1,
						area: [common.isModile()?'100%':'500px', common.isModile()?'100%':'700px'],
						content: 'register.html'
					});
					return false;
				})
			})
		</script>
	</body>
</html>
